package com.huika.renrench.control.common.base;

import java.security.Security;

import android.app.Application;

import com.hk.app.android.lib.http.VolleyRequestManager;
import com.huika.lib.utils.CrashHandler;
import com.huika.lib.utils.DebugTool;
import com.huika.lib.utils.ImgCacheUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

public class BaseApp extends Application {
	public static int SCREEN_WIDTH;
	public static int SCREEN_HEIGHT;
	private static BaseApp instance;
	
	public static BaseApp getInstance() {
		return instance;
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		CrashHandler.getInstance(this);
		instance = this;
		
		SCREEN_WIDTH = getResources().getDisplayMetrics().widthPixels;
		SCREEN_HEIGHT = getResources().getDisplayMetrics().heightPixels;
		
		initHttp();
		
		ImageLoader.getInstance().init(ImgCacheUtil.getInstance(this).getImgLoaderConfig());
	}
	
	// 初始话网络请求
	private void initHttp(){
		/**
		 * dns解析相关
		 * "networkaddress.cache.ttl"表示查询成功的缓存，
		 * "networkaddress.cache.negative.ttl"表示查询失败的缓存。
		 * 第二个参数表示缓存有效时间，单位是秒。
		 */
		Security.setProperty("networkaddress.cache.ttl", String.valueOf(10 * 60));  
		Security.setProperty("networkaddress.cache.negative.ttl", String.valueOf(0));
		
		VolleyRequestManager.init(this, DebugTool.IS_LOG);
//		String userAgent = "volley/0";
//		HttpStack stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
//		VolleyRequestManager.init(this, stack, Configuration.IS_DEBUG_ENABLE);
	}
}
